package com.zelin.yang.kotlin_demo.util

import android.annotation.SuppressLint
import android.support.design.internal.BottomNavigationItemView
import android.support.design.internal.BottomNavigationMenuView
import android.support.design.widget.BottomNavigationView
import android.util.Log
import java.lang.reflect.Field

class BottomNavigationViewHelper {
    val TAG1:String = BottomNavigationViewHelper.javaClass.simpleName
    /**
     *需要伴生对象来实现
     */
    companion object {
        @SuppressLint("RestrictedApi")
        fun disableShiftMode(view: BottomNavigationView){
           try {
               val menuView: BottomNavigationMenuView = view.getChildAt(0) as BottomNavigationMenuView
               //利用反射找到该方法
               val  shiftingMode: Field = menuView.javaClass.getDeclaredField("mShiftingMode")
               shiftingMode.isAccessible = true
               shiftingMode.setBoolean(menuView,true)
               shiftingMode.isAccessible = false
               for (i in 0 until menuView.childCount){
                   var item: BottomNavigationItemView = menuView.getChildAt(i) as BottomNavigationItemView
                   item.setShifting(false)
                   item.setChecked(item.getItemData().isChecked());
               }
           } catch (e:Exception){
               e.message
                Log.i("抛出来的异常",e.message)
           }
        }
    }
}




